<?php
/*
$fh = fopen('log.txt','w+');
fwrite($fh,'sessionid:'.$_COOKIE[session_name()]);
fwrite($fh, print_r($_REQUEST,true));
fclose($fh);
*/
if(isset($_REQUEST[session_name()]))
	$_COOKIE[session_name()] = $_REQUEST[session_name()];
include('_init_.php');
//permission check
include(constant('APP_DIR').'/web-admin/permission-check.php');
// JQuery File Upload Plugin v1.4.1 by RonnieSan - (C)2009 Ronnie Garcia
if (!empty($_FILES)) {


	$tempFile = $_FILES['Filedata']['tmp_name'];
	$file_type = substr($_FILES['Filedata']['name'], strrpos($_FILES['Filedata']['name'], "."));
	
	$websitePath = '/img/tmp/';
	$uploadDir = constant('SITE_WEB_DISK_DIR').$websitePath;
	if(!file_exists($uploadDir))
	{
		mkdir($uploadDir,0755,true);
	}
	$fileName = time().Util::makeRandomStr(3).$file_type;
	$targetFile =  str_replace('//','/',$uploadDir) . $fileName ;

	
	move_uploaded_file($tempFile,$targetFile);
	
	$response = '';
	$responsetype = isset($_REQUEST['responsetype'])?$_REQUEST['responsetype']:'';
	switch($responsetype)
	{
		case 'sizeinfo':
			list($width, $height, $type, $attr) = getimagesize($targetFile);
			$response = sprintf("{'name':'%s','w':%d,'h':%d}",$fileName,$width, $height);
		break;
		case 'filecontent':
			$response = file_get_contents($targetFile);
			break;
		default:
		$response = $fileName;
		break;
	}
	echo $response;
}
?>
